/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.icanci.coupon.utils;

import cn.hutool.core.lang.UUID;
import cn.icanci.coupon.entity.CouponEntity;

/**
 * @author icanci
 * @date Created in 2021/05/01 14:59
 * @version 1.0
 */
@SuppressWarnings("all")
public class CouponUtils {
    private static final String prefix = "ECICC";

    /**
     * 生成 CouponNumber
     * @param couponEntity 优惠券实体
     * @return 返回唯一 CouponNumber
     */
    public static String getUniqueKeyCouponNumber(CouponEntity couponEntity, Integer index) {
        StringBuilder builder = new StringBuilder();
        UUID uuid = UUID.randomUUID();
        // CouponNumber 含义
        // 头缀_满_减_类型_总数_第几个_唯一编号
        builder.append(prefix).append("_")//
            .append(couponEntity.getFullMoney()).append("_")//
            .append(couponEntity.getReduceMoney()).append("_")//
            .append(couponEntity.getCouponType()).append("_")//
            .append(couponEntity.getTotalNum()).append("_")//
            .append(index).append("_")//
            .append(uuid.toString().replace("-", "").substring(0, 10));
        return builder.toString().toUpperCase();
    }

    /**
     * 获取同一批次优惠券唯一key
     * @return
     */
    public static String getUniqueKey() {
        UUID uuid = UUID.randomUUID();
        return uuid.toString().replace("-", "").substring(0, 10).toUpperCase();
    }
}
